package com.supreme.studyserver.controller;

import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.studyserver.service.AbsService;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/spring")
public class SpringController {

    @Resource
    private BeanFactory beanFactory;

    @Resource
    private ApplicationContext applicationContext;

    @GetMapping(value = "/beanFactory")
    public AjaxResp beanFactory() {
        AbsService absService = beanFactory.getBean(AbsService.class);
        absService.showMessage();
        return AjaxResp.instance();
    }

    @GetMapping(value = "/applicationContext")
    public AjaxResp applicationContext() {
        System.out.println("applicationContext = " + applicationContext);
        AbsService absService = applicationContext.getBean(AbsService.class);
        absService.showMessage();
        return AjaxResp.instance();
    }
}
